package com.ks.core.api.config;

import com.ks.core.api.RateLimiterInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author kingdee
 */
@Configuration()
@ConditionalOnProperty(value = "api.limit.enabled", havingValue = "true")
public class RateLimiterConfiguration implements WebMvcConfigurer {

    @Resource
    private ApiConfig apiConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RateLimiterInterceptor(apiConfig));
    }
}
